package com.bl.weilan.manager.controller.informationType;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.service.biz.informationType.InformationTypeService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.information.InformationAddVo;
import com.bl.weilan.service.vo.informationtype.InformationTypeListVo;
import com.bl.weilan.service.vo.informationtype.InformationTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/informationtype"})
@Api(value = "通知类型相关", description = "通知类型相关manager")
public class InformationTypeController {

    @Autowired
    InformationTypeService informationTypeService;

    @ApiOperation(value = "查询通知类型列表", notes = "查询通知类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_infotype_list"})
    public ApiResponseBody<InformationTypeListVo> informationTypeList(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,

            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        InformationTypeListVo informationTypeListVo = informationTypeService.getInformationTypeList(pageable);

        return ApiResponseBody.createSuccessBody(informationTypeListVo);
    }


    @ApiOperation(value = "新增通知类型", notes = "新增通知类型 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add_type"})
    public ApiResponseBody add(
            @Valid @RequestBody InformationTypeVo body, BindingResult result,
            HttpServletRequest request) {

//        ApiResponseBody validResult = validParams(result);
//        if (validResult != null) {
//            return validResult;
//        }

        informationTypeService.add(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一个类型", notes = "删除类型 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        informationTypeService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }




}
